//
// Created by 123 on 2025/1/9.
//
#include "set"
#include "iostream"
using namespace std;

class MyCompare{
public:
    bool operator()(int v1,int v2) const{
        return v1>v2;
    }
};

void printSet(set<int> s){
    for(int d:s){
        cout << d << " ";
    }
    cout << endl;
}

void test(){
    set<int> s1;
    s1.insert(10);
    s1.insert(50);
    s1.insert(30);
    s1.insert(40);
    s1.insert(20);
    printSet(s1);

    set<int,MyCompare> s2;
    s2.insert(10);
    s2.insert(50);
    s2.insert(30);
    s2.insert(40);
    s2.insert(20);
    for(set<int,MyCompare>::iterator it = s2.begin();it != s2.end();it++){
        cout << *it << " ";
    }
    cout << endl;
}

class Person{
public:
    string name;
    int age;
public:
    Person(string name,int age){
        this->name = name;
        this->age = age;
    }
};

class ComparePerson{
public:
    bool operator()(const Person& p1,const Person& p2) const{
        return p1.age > p2.age;
    }
};

void test2(){
    set<Person,ComparePerson> s ;
    Person p1("zs",55);
    Person p2("lis",66);
    Person p3("ww",22);
    Person p4("ff",31);
    s.insert(p1);
    s.insert(p2);
    s.insert(p3);
    s.insert(p4);

    for(set<Person,ComparePerson>::iterator it=s.begin();it != s.end();it++){
        cout << "name=" << (*it).name << " age:" << it->age << " ";
        cout << endl;
    }


}

int main140(){
    test();
    test2();
    return 0;
}